package com.translate.service.service.task;

import com.translate.commons.asynctask.AsyncTaskBase;
import com.translate.commons.asynctask.AsyncTaskExecutor;
import com.translate.commons.utils.SpringContextHelper;

import javax.annotation.Resource;

/**
 * 自定义的线程
 * 如果用springboot的线程就不用这个
 */
public class DemoTask extends AsyncTaskBase {

    private String demoF; // 传进来的参数
    @Resource
    private AsyncTaskExecutor asyncTaskExecutor;
    @Resource
    DemoService demoService;

    public DemoTask(SpringContextHelper sch, String demoF) {
        super(sch, new Object[] { demoF });
    }

    @Override
    public void execute() {
        try {
            // 写业务逻辑
            demoService.method(demoF);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            asyncTaskExecutor.complate(this.getTaskId(), this);
        }
    }

    @Override
    public int getProgress() {
        return 0;
    }

    @Override
    public Object getResult() {
        return null;
    }

}
